package cn.imvc.app.controllers.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.entities.Department;
import cn.imvc.app.models.DepartmentModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

public class DepartmentControllerImpl implements DepartmentController {
	public Page<Department> page;
	public ViewRequest viewRequest;
	public Department department;
	public String departmentTree;
	public String depTree;
	public int id;
	
	public void setId(int id) {
		this.id = id;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}
	@Autowired
	DepartmentModel departmentModel;
	
	public String search() {
		return null;
	}

	public String index() {
		departmentTree=departmentModel.getDepartmentTree();
		return "department/index";
	}

	public String show() {
		department=departmentModel.get(id);
		return "department/show";
	}

	public String editNew() {
		department=departmentModel.get(id);
		return "department/editNew";
	}

	public String create() {
		departmentModel.save(id,department);
		return Render.json(new DialogBean("200", "创建成功","department","closeCurrent"));
	}

	public String edit() {
		department=departmentModel.get(id);
		return "department/edit";
	}

	public String update() {
		departmentModel.update(id,department);
		return Render.json(new DialogBean("200", "修改成功","department"));
	}

	public String destroy() {
		return Render.json(departmentModel.delete(id));
	}

	public String destroyBatch() {
		return null;
	}
	
	public String treeLookup(){
		
		depTree=departmentModel.treeLookup();
		return "department/treeLookup";
	}
	
	public String lookupSuggest(){
		return Render.json(departmentModel.lookupSuggest());
	}

}
